﻿/// <reference path="Solution.Admin.jCommon.js" />

if (typeof (Solution) == 'undefined') Solution = {};
if (typeof (Solution.Admin) == 'undefined') Solution.Admin = {};
Solution.Admin.SysConfigRoleGroup = {
    Init: function () {
        this.Create();
    },
    gridID: '#List',
    CreateGrid: function (Url, UrlEdit, EditAdvance, GroupID) {
        var thisObj = this;
        var Pager = thisObj.gridID + 'Pager';
        var lastselobj = { lastsel: 0 };
        var lastselObj = lastselobj;
        var flagEdit = false;
        if (typeof GroupID != 'undefined') {
            Url += '?GroupID=' + GroupID;
        }

        $(thisObj.gridID).jqGrid({
            url: Url,
            datatype: 'json',
            mtype: 'GET',
            colNames: ['Id', 'Module Name', 'View', 'Add', 'Delete', 'Update', 'All'],
            colModel: [
                            { name: 'Id', index: 'Id', width: 40, align: 'left', editable: false, editoptions: { readonly: true} },
                            { name: 'ModuleName', index: 'ModuleName', width: 300, align: 'left', editable: false },
                            { name: 'View', index: 'View', width: 50, align: 'center', editable: true, edittype: "checkbox", editoptions: { value: "True:False"} },
                            { name: 'Insert', index: 'Insert', width: 50, align: 'center', editable: true, edittype: "checkbox", editoptions: { value: "True:False"} },
                            { name: 'Delete', index: 'Delete', width: 50, align: 'center', editable: true, edittype: "checkbox", editoptions: { value: "True:False"} },
                            { name: 'Update', index: 'Update', width: 50, align: 'center', editable: true, edittype: "checkbox", editoptions: { value: "True:False"} },
                            { name: 'All', index: 'All', width: 50, align: 'center', editable: true, edittype: "checkbox", editoptions: { value: "True:False"} }

                          ],
            rowNum: 20,
            rowList: [10, 20, 50],
            height: 380,
            width: 600,
            sortname: 'Id',
            sortorder: "asc",
            editurl: UrlEdit,
            multiselect: false,
            shrinkToFit: true,
            rownumbers: true,
            jsonReader: {
                root: "rows",
                page: "page",
                total: "total",
                records: "records",
                repeatitems: true,
                id: "0"
            },
            onSelectRow: function (id) {
                if (flagEdit == true) {
                    //jQuery("#grid_id").jqGrid('saveRow', rowid, succesfunc, url, extraparam, aftersavefunc, errorfunc, afterrestorefunc);
                    jQuery(thisObj.gridID).jqGrid('saveRow', lastsel, function (response, postdata) {
                        if (response.responseText == '"ok"') {
                            Solution.Admin.Core.ShowNotif('s', 0); thisObj.ReloadGrid();
                        }
                        else
                            if (response.responseText == '"err"')
                                Solution.Admin.Core.ShowNotif('e', -1);
                        return false;
                    });
                    jQuery(thisObj.gridID).jqGrid('restoreRow', lastsel);
                    flagEdit = false;
                }
                jQuery(thisObj.gridID).jqGrid('editRow', id, true, '', function (response, postdata) { if (response.responseText != '"err"') { Solution.Admin.Core.ShowNotif('s', 0); thisObj.ReloadGrid(); } else Solution.Admin.Core.ShowNotif('e', -1); return true; }, ''); //  ('editRow', rowid, keys, oneditfunc, succesfunc, url, extraparam, aftersavefunc, errorfunc, afterrestorefunc);
                lastsel = id;
                flagEdit = true;
            },
            delSettings: function () {
            },
            ondblClickRow: function (id) {

            },
            caption: ''
        });

    },
    Create: function () {
        Solution.Admin.jCommon.CreateNews(this.gridID);
    },
    ReloadGrid: function () {
        Solution.Admin.jCommon.ReloadGrid(this.gridID);
    },
    ShowBin: function (Url, showBin) {
        Solution.Admin.jCommon.ShowBin(this.gridID, Url, showBin);
    },
    DeleteRows: function (_URL, delForever) {
        Solution.Admin.jCommon.DeleteRows(this.gridID, _URL, delForever);
    }
}
